home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2005 August / PCpro_2005_08.ISO / files / digifoto / winmorph / setup.exe / {code:GetWaxDir} / Plugins / Scripts / DISSOLVE.C < prev    next >
Encoding:
Text File  |  2003-03-02  |  4.4 KB  |  158 lines

  1. int DissolveMain(HANDLE hStream, ImagePluginApplyParams *psParams,
  2.                  int r, int g, int b, int bCross)
  3. {
  4.     int nSrcPercent, nLength, i;
  5.     ImageSample *psSrcSample, *psDstSample;
  6.     DWORD dwPos;
  7.  
  8.     nLength = psParams->dwWidth*psParams->dwHeight;
  9.  
  10.     // if reverse dir, change the frame pos appropriately.
  11.     dwPos = psParams->dwPos;
  12.     dwPos = psParams->dwFrames-1-psParams->dwPos;
  13.  
  14.     if (bCross)
  15.     {
  16.         // cross dissolve.
  17.  
  18.         int bAlphaZero = 0;
  19.         nSrcPercent = 0;
  20.         if (psParams->dwFrames > 1)
  21.             nSrcPercent = (dwPos*256)/(psParams->dwFrames-1);
  22.  
  23.         if (!psParams->bBelow)
  24.         {
  25.             nSrcPercent = 256-nSrcPercent;
  26.         }
  27.         // double the slope and clip it at 256.
  28.         // (draw the graph and see, you'll understand)
  29.         nSrcPercent *= 2;
  30.         if (nSrcPercent > 256)
  31.         {
  32.             nSrcPercent = 256;
  33.             if (psParams->bAboveEnabled && psParams->bBelowEnabled)
  34.                 bAlphaZero = 1;        // alpha zero only if both are enabled.
  35.                                     // else, this shortcut will be exposed badly...
  36.         }
  37.  
  38.         psSrcSample = psParams->psSrcSample;
  39.         psDstSample = psParams->psDstSample;
  40.  
  41.         if (bAlphaZero)
  42.         {
  43.             while (nLength--)
  44.             {
  45.                 psDstSample->a = 0;
  46.                 psDstSample++;
  47.             }
  48.         }
  49.         else
  50.         {
  51.             while (nLength--)
  52.             {
  53.                 psDstSample->r = psSrcSample->r+(((r-psSrcSample->r)*nSrcPercent)>>8);
  54.                 psDstSample->g = psSrcSample->g+(((g-psSrcSample->g)*nSrcPercent)>>8);
  55.                 psDstSample->b = psSrcSample->b+(((b-psSrcSample->b)*nSrcPercent)>>8);
  56.                 psDstSample->a = psSrcSample->a;
  57.                 psSrcSample++;
  58.                 psDstSample++;
  59.             }
  60.         }
  61.     }
  62.     else
  63.     {
  64.         // calculate the percentage of each of the source frame.
  65.         nSrcPercent = 0;
  66.         if (psParams->dwFrames > 1)
  67.             nSrcPercent = (dwPos*256)/(psParams->dwFrames-1);
  68.  
  69.         if (psParams->bBelow)
  70.         {
  71.             if (psParams->bAboveEnabled)
  72.                 nSrcPercent = 256;
  73.             else
  74.                 nSrcPercent = 256-nSrcPercent;
  75.         }
  76.  
  77.         psSrcSample = psParams->psSrcSample;
  78.         psDstSample = psParams->psDstSample;
  79.         i = nLength % 8;
  80.         nLength /= 8;
  81.         while (i--)
  82.         {
  83.             psDstSample->r = psSrcSample->r;
  84.             psDstSample->g = psSrcSample->g;
  85.             psDstSample->b = psSrcSample->b;
  86.             psDstSample->a = (psSrcSample->a * nSrcPercent)>>8; // only modify Alpha!
  87.             psSrcSample++;
  88.             psDstSample++;
  89.         }
  90.         while (nLength--)
  91.         {
  92.             unsigned int p1;
  93.             unsigned int *ptr1, *ptr2;
  94.             ptr1 = (unsigned int *)psSrcSample;
  95.             ptr2 = (unsigned int *)psDstSample;
  96.  
  97.             p1 = *(ptr1+0); *(ptr2+0) = p1; *((unsigned char *)(ptr2+0)+3) = ((p1>>24)*nSrcPercent)>>8;
  98.             p1 = *(ptr1+1); *(ptr2+1) = p1; *((unsigned char *)(ptr2+1)+3) = ((p1>>24)*nSrcPercent)>>8;
  99.             p1 = *(ptr1+2); *(ptr2+2) = p1; *((unsigned char *)(ptr2+2)+3) = ((p1>>24)*nSrcPercent)>>8;
  100.             p1 = *(ptr1+3); *(ptr2+3) = p1; *((unsigned char *)(ptr2+3)+3) = ((p1>>24)*nSrcPercent)>>8;
  101.             p1 = *(ptr1+4); *(ptr2+4) = p1; *((unsigned char *)(ptr2+4)+3) = ((p1>>24)*nSrcPercent)>>8;
  102.             p1 = *(ptr1+5); *(ptr2+5) = p1; *((unsigned char *)(ptr2+5)+3) = ((p1>>24)*nSrcPercent)>>8;
  103.             p1 = *(ptr1+6); *(ptr2+6) = p1; *((unsigned char *)(ptr2+6)+3) = ((p1>>24)*nSrcPercent)>>8;
  104.             p1 = *(ptr1+7); *(ptr2+7) = p1; *((unsigned char *)(ptr2+7)+3) = ((p1>>24)*nSrcPercent)>>8;
  105.             psSrcSample += 8;
  106.             psDstSample += 8;
  107.         }
  108.     }
  109.  
  110.     return 0;
  111. }
  112.  
  113. int Dissolve(HANDLE hStream, ImagePluginApplyParams *psParams)
  114. {
  115.     return DissolveMain(hStream, psParams, 255, 255, 0, 0);
  116. }
  117.  
  118. int DissolveThroBlack(HANDLE hStream, ImagePluginApplyParams *psParams)
  119. {
  120.     return DissolveMain(hStream, psParams, 0, 0, 0, 1);
  121. }
  122.  
  123. int DissolveThroWhite(HANDLE hStream, ImagePluginApplyParams *psParams)
  124. {
  125.     return DissolveMain(hStream, psParams, 255, 255, 255, 1);
  126. }
  127.  
  128. int DissolveThroRed(HANDLE hStream, ImagePluginApplyParams *psParams)
  129. {
  130.     return DissolveMain(hStream, psParams, 255, 0, 0, 1);
  131. }
  132.  
  133. int DissolveThroGreen(HANDLE hStream, ImagePluginApplyParams *psParams)
  134. {
  135.     return DissolveMain(hStream, psParams, 0, 255, 0, 1);
  136. }
  137.  
  138. int DissolveThroBlue(HANDLE hStream, ImagePluginApplyParams *psParams)
  139. {
  140.     return DissolveMain(hStream, psParams, 0, 0, 255, 1);
  141. }
  142.  
  143. int DissolveThroCyan(HANDLE hStream, ImagePluginApplyParams *psParams)
  144. {
  145.     return DissolveMain(hStream, psParams, 0, 255, 255, 1);
  146. }
  147.  
  148. int DissolveThroMagenta(HANDLE hStream, ImagePluginApplyParams *psParams)
  149. {
  150.     return DissolveMain(hStream, psParams, 255, 0, 255, 1);
  151. }
  152.  
  153. int DissolveThroYellow(HANDLE hStream, ImagePluginApplyParams *psParams)
  154. {
  155.     return DissolveMain(hStream, psParams, 255, 255, 0, 1);
  156. }
  157.  
  158.